<template>
	<view class="lesson-page">
		<view class="add-lession" @click="goAddLession">
			<u-icon name="plus-circle-fill" color="#FF9900" size="32" label="新建班级"></u-icon>
		</view>
		<nodate v-if="list.length<1" />
		<scroll-view :scroll-top="scrollTop" scroll-y="true" class="list-box" v-else>
			<u-card margin="20rpx" v-for="(el,i) in list" :key="i" :show-foot="false">
				<view slot="head" class="u-flex u-row-between">
					<text class="u-font-34 yu-bold">{{el.weekdayname}}</text>
					<text><text class="yu-bold u-font-40 yu-color-money u-m-r-10">{{el.empClassList.length}}</text>节课</text>
				</view>
				<view class="" slot="body">
					<u-collapse :arrow="true">
						<u-collapse-item v-for="(e,n) in el.empClassList">
							<view class="u-flex yu-between yu-flex-1" slot="title">
								<text>{{e.starttime+'~'+e.endtime+'【'+e.classname+'】'}}</text>
								<view class="u-p-r-20" @click="goAdjust(e)" v-if="roleType==2">
									<u-icon name="man-add-fill" color="#FF9900" size="32" label="调整"></u-icon>
								</view>
							</view>
							<view class="u-flex yu-between u-p-r-10" v-for="(stu,l) in e.stuClassList" :key="l">
								<view class="u-flex yu-start">
									<u-avatar :src="$api.json('baseUrl')+'/upload/'+stu.headimg"></u-avatar>
									<view class="u-p-l-20 u-font-34 yu-color-3">
										{{stu.stuname +' '+stu.phone}}
									</view>
								</view>
								<u-icon name="edit-pen-fill" color="#FF9900" size="48" @click="goSing(stu)" v-if="roleType==2"></u-icon>

							</view>
						</u-collapse-item>
					</u-collapse>
				</view>
			</u-card>
		</scroll-view>
		<u-popup v-model="showPop" mode="center" border-radius="14" :closeable="true" width="520rpx">
			<view class="u-p-20 u-m-t-40 u-m-b-40">
				<view class="u-font-34 yu-bold yu-color-3 u-text-center">{{operItem.stuname}}</view>
				<u-form :model="singForm" ref="uForm">
					<u-form-item label="类型:" prop="status">
						<u-radio-group v-model="singForm.status" active-color="#FF9900">
							<u-radio :name="1">正常</u-radio>
							<u-radio :name="2">请假</u-radio>
							<u-radio :name="3">补课</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="内容:" prop="content">
						<u-input v-model="singForm.content" type="textarea" :border="true" :auto-height="true" :height="50" />
					</u-form-item>
					<u-form-item label="">
					</u-form-item>
				</u-form>
				<u-button type="warning" :ripple="true" ripple-bg-color="#909399" @click="singSave">点名</u-button>
			</view>
		</u-popup>
		<adjust-stu ref="adjust_stu" @adjustOver="adjustOver"></adjust-stu>
	</view>
</template>

<script>
	import adjustStu from '../../components/adjustStu.vue'
	export default {
		components:{
			adjustStu,
		},
		data() {
			return {
				showPop: false,
				singForm: {
					status: 1,
					content: ''
				},
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				wagesheight: '500',
				list: [],
				operItem: {},
				rules: {
					content: [{
						required: true, 
						message: '课程内容必填',
						trigger: 'change'
					}]
				}
			}
		},
		computed:{
			singData(){
				const {status, content} = this.singForm
				return {
					status,
					content,
					paymentid:this.operItem.paymentid
				}
			},
			roleType(){
				return sessionStorage.getItem('role')
			}
		},
		onLoad() {
			this.getData()
		},
		onPullDownRefresh(){
			this.list = []
			this.getData()
		},
		methods: {
			radioGroupChange(e) {
				this.singForm.status = e
			},
			goSing(item) {
				this.operItem = item
				this.singForm = {
					status: 1,
					content: ''
				}
				this.showPop = true
				setTimeout(()=>{this.$refs.uForm.setRules(this.rules);}, 10)
			},
			singSave() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$http('/lession/h5doSign',this.singData, (res) => {
							this.showPop = false
							this.getData()
						})
					}
				});
			},
			goAdjust(val){
				this.$refs.adjust_stu.init(val)
			},
			goAddLession(val){
				uni.navigateTo({
					url:'addlessino'
				})
			},
			lower() {
				console.log(11);
			},
			adjustOver(){
				this.list = []
				this.getData()
			},
			getData() {
				this.$http('/class/findEmpClass', {}, (res) => {
					this.list = res.data
					uni.stopPullDownRefresh()
				})
			}
		}
	}
</script>

<style>
	.list-box {
		height: 100vh
	}
	.add-lession{
		position: fixed;
		top: 26rpx;
		right: 30rpx;
		z-index: 999;
	}
</style>
